<?php
header("Content-type:text/html; charset=utf-8;");
require '../../../ppf/fun.php';
require '../../../ppf/pdo_mysql.php';
require '../../../ppf/Filter.php';
date_default_timezone_set("PRC");
$pd=new pdo_mysql();
$filter=new Filter();
session_start();
if(empty($_SESSION['uid'])){
	echo '请登录后再进行操作';exit;
}
$submitMethod=$_SERVER["REQUEST_METHOD"];
if($submitMethod=='POST'){
    $now=date('Y-m-d H:i:s',time());
    $no_flag       = empty($_POST['no_flag'])?'':$_POST['no_flag'];
	$sender       = empty($_POST['uid'])?"":$_POST['uid'];
	$accept_id   = empty($_POST['accept_id'])?'':Filter::filter_html($_POST['accept_id']);
    $content      = empty($_POST['content'])?"":$_POST['content'];
	$geter_id = explode(',',$accept_id);
	$flag = implode(',',$no_flag);
	$in_data=array(
			'sender'  =>$sender,
			'content'    =>$content,
			'time'       =>$now,
			'accepter'  =>$accept_id,
			'no_flag' =>$flag
	    );
	$pd->insert(array('data'=>$in_data,'table'=>'sys_notice'));
	$nid = $pd->lastInsertId();
	$SY=0;$SN=0;$MY=0;$MN=0;$count = count($geter_id);
	$tips='';
	$up_data1=array();$up_data2=array();$up_data3=array('count'=>$count);
	if(in_array(1, $no_flag)){//系统通知
		for($i=0;$i<$count;$i++){
			$in_data=array(
				'nid' =>$nid,
				'sender'  =>$sender,
				'content'    =>$content,
				'accepter'   =>$geter_id[$i],
				'time'       =>date('Y-m-d H:i:s',time())
		    );
			
			$result=$pd->insert(array('data'=>$in_data,'table'=>'sys_notice_list'));
			if($result){
				$SY++;
			}
		}
		$SN = $count-$SY;
		$tips.='系统通知发送完成，成功'.$SY.'条，失败'.$SN.'条。';
		$up_data1=array(
			's_success' =>$SY,
			's_fail'  =>$SN,
	    );
	}
	if(in_array(2, $no_flag)){//手机短信通知
		$tips.='手机短信通知发送完成，成功'.$MY.'条，失败'.$MN.'条。';
		$up_data2=array(
			'm_success' =>$MY,
			'm_fail'  =>$MN,
	    );
	}
	$up_data=array_merge($up_data1,$up_data2,$up_data3);
	$pd->update(array('data'=>$up_data,'table'=>'sys_notice','where'=>"id=".$nid));
	
	echo $tips;exit;
}else{
	echo '不允许的表单提交方式，请按正常流程提交表单。';exit;
}
?>